﻿#include "patternmanagewidget.h"
#include "ui_patternmanagewidget.h"

PatternManageWidget::PatternManageWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PatternManageWidget),
    m_itemPerPage(16)
{
    ui->setupUi(this);
    setWindowFlags (Qt::Window | Qt::FramelessWindowHint);
    setWindowModality(Qt::ApplicationModal);

    m_mousePressX = 0;
    m_mousePressY = 0;
    m_mouseReleaseX = 0;
    m_mouseReleaseY = 0;

    m_itemBtnList.clear();

    m_itemBtnList.append(ui->button1);
    m_itemBtnList.append(ui->button2);
    m_itemBtnList.append(ui->button3);
    m_itemBtnList.append(ui->button4);
    m_itemBtnList.append(ui->button5);

    ui->button6->setVisible(false);//隐藏
    ui->button7->setVisible(false);
    ui->button8->setVisible(false);
    ui->button9->setVisible(false);
    ui->button10->setVisible(false);
    ui->button11->setVisible(false);

      {
          ui->button6->setVisible(true);//显示
          ui->button7->setVisible(true);
          ui->button8->setVisible(true);
          m_itemBtnList.append(ui->button6);
          m_itemBtnList.append(ui->button7);
          m_itemBtnList.append(ui->button8);
      }


    m_itemBtnList.append(ui->button12);
    m_itemBtnList.append(ui->button13);
    m_itemBtnList.append(ui->button14);
    m_itemBtnList.append(ui->button15);
    m_itemBtnList.append(ui->button16);
    ui->button17->setVisible(false);//隐藏
    ui->button18->setVisible(false);
    ui->button19->setVisible(false);
    ui->button20->setVisible(false);
    ui->button21->setVisible(false);
    ui->button22->setVisible(false);

	{
        ui->button17->setVisible(true);
        ui->button18->setVisible(true);
        ui->button19->setVisible(true);
        m_itemBtnList.append(ui->button17);
        m_itemBtnList.append(ui->button18);
        m_itemBtnList.append(ui->button19);
    }

    initControl();
    initialize();
}

PatternManageWidget::~PatternManageWidget()
{
    delete ui;
}

//初始化
void PatternManageWidget::initialize()
{
    m_curPages = 1;
    m_pageNums = 1;
    m_fileItemList.clear();//文件列表清空
    m_selectFileItemList.clear();
    m_rootPath.clear();//操作屏根路径
    m_curPath.clear();//当前路径
    m_selectAll = -1;

    QDir apppath(qApp->applicationDirPath());
    QString filePath = apppath.path() + apppath.separator() + PATTERNPATH;
    m_rootPath = QDir(filePath).absolutePath();//为了将"\"变为"/"
}

//初始化窗体控件，包括位置、尺寸、样式
void PatternManageWidget::initControl()
{
    //根据不同分辨率设置控件的位置和尺寸
    initResolution();
    initControlStyle();//初始化窗体控件样式
}

//初始化窗体控件为任意分辨率
void PatternManageWidget::initResolution()
{
    double factoryX = getFactoryX();
    double factoryY = getFactoryY();

    this->resize(GLB_SCR_WIGHT*factoryX,GLB_SCR_HEIGHT*factoryY);
    ui->frameBack->setGeometry(0*factoryX,0*factoryY,GLB_SCR_WIGHT*factoryX,GLB_SCR_HEIGHT*factoryY);
    ui->buttonTypeLogo->setGeometry(GLB_EDGE_WIGHT*factoryX,GLB_EDGE_HEIGHT*factoryY,GLB_LICON_SIZE*factoryX,GLB_LICON_SIZE*factoryY);
    ui->labelMainTitle->setGeometry((GLB_EDGE_WIGHT+GLB_LICON_SIZE+GLB_EDGE_WIGHT)*factoryX,GLB_EDGE_HEIGHT*factoryY,
                                    (GLB_SCR_WIGHT-(GLB_EDGE_WIGHT+GLB_LICON_SIZE+GLB_EDGE_WIGHT*2))*factoryX,GLB_TEXT_L_HEIGHT*factoryY);
    ui->labelSubTitle->setGeometry((GLB_EDGE_WIGHT+GLB_LICON_SIZE+GLB_EDGE_WIGHT+GLB_TAB_WIGHT)*factoryX,(GLB_EDGE_HEIGHT+GLB_LICON_SIZE-GLB_TEXT_HEIGHT)*factoryY,
                                   (GLB_SCR_WIGHT-(GLB_EDGE_WIGHT+GLB_LICON_SIZE+GLB_EDGE_WIGHT+GLB_TAB_WIGHT*2))*factoryX,GLB_TEXT_HEIGHT*factoryY);

    ui->labelPage->setGeometry(48*factoryX,0,200*factoryX,70*factoryY);
    ui->labelPage->setAlignment(Qt::AlignLeft);

    QRect rectImage(0*factoryX,0*factoryY,26*factoryX,28*factoryY);
    QRect rectName(33*factoryX,-5*factoryY,200*factoryX,36*factoryY);//花样名称
    for(int i = 0; i < 2; i++)
    {
        s16 num = m_itemBtnList.size()/2;
        for(int j = 0; j < num; j++)
        {
            m_itemBtnList[i*num + j]->setLabelFont(fontSize_M());
            m_itemBtnList[i*num + j]->setGeometry((44+i*378)*factoryX,(138+j*47)*factoryY,337*factoryX,38*factoryY);
            m_itemBtnList[i*num + j]->initLeftImageRightName(rectImage,rectName);
        }
    }

    ui->frameRightUp->setGeometry(800*factoryX,40*factoryY,800*factoryX,61*factoryY);
    ui->buttonBackUpDir->setGeometry(150*factoryX,0,50*factoryX,50*factoryY);
    ui->buttonSelectAll->setGeometry(93*factoryX,0,50*factoryX,50*factoryY);
    ui->buttonNewFolder->setGeometry(37*factoryX,0,50*factoryX,50*factoryY);

    ui->labelPatternView->setGeometry(806*factoryX,152*factoryY,161*factoryX,137*factoryY);
    ui->labelNameValue->setGeometry(816*factoryX,315*factoryY,146*factoryX,22*factoryY);

    ui->labelX->setGeometry(816*factoryX,350*factoryY,141*factoryX,20*factoryY);
    ui->labelY->setGeometry(816*factoryX,375*factoryY,91*factoryX,20*factoryY);
    ui->labelW->setGeometry(816*factoryX,400*factoryY,91*factoryX,20*factoryY);
    ui->labelH->setGeometry(816*factoryX,425*factoryY,91*factoryX,20*factoryY);
    ui->labelC->setGeometry(816*factoryX,450*factoryY,91*factoryX,20*factoryY);
    ui->labelN->setGeometry(816*factoryX,475*factoryY,91*factoryX,20*factoryY);

    ui->labelXValue->setGeometry(865*factoryX,350*factoryY,91*factoryX,20*factoryY);
    ui->labelYValue->setGeometry(865*factoryX,375*factoryY,91*factoryX,20*factoryY);
    ui->labelWValue->setGeometry(865*factoryX,400*factoryY,91*factoryX,20*factoryY);
    ui->labelHValue->setGeometry(865*factoryX,425*factoryY,91*factoryX,20*factoryY);
    ui->labelCValue->setGeometry(865*factoryX,450*factoryY,91*factoryX,20*factoryY);
    ui->labelNValue->setGeometry(865*factoryX,475*factoryY,91*factoryX,20*factoryY);

    ui->framePageBtn->setGeometry(0*factoryX,(GLB_SCR_HEIGHT-GLB_LBUT_HEIGHT-GLB_EDGE_WIGHT)*factoryY,GLB_SCR_WIGHT*factoryX,GLB_LBUT_HEIGHT*factoryY);
    ui->labelPage->setGeometry(GLB_EDGE_WIGHT*factoryX,(GLB_SCR_HEIGHT-GLB_TEXT_HEIGHT-GLB_EDGE_WIGHT)*factoryY,(GLB_SCR_WIGHT/3)*factoryX,GLB_TEXT_HEIGHT*factoryY);
    ui->buttonPgUp->setGeometry((GLB_SCR_WIGHT-(GLB_EDGE_WIGHT+GLB_BAS_WIGHT*3+GLB_LBUT_WIGHT*4))*factoryX,0*factoryY,GLB_LBUT_WIGHT*factoryX,GLB_LBUT_HEIGHT*factoryY);
    ui->buttonPgDn->setGeometry((GLB_SCR_WIGHT-(GLB_EDGE_WIGHT+GLB_BAS_WIGHT*2+GLB_LBUT_WIGHT*3))*factoryX,0*factoryY,GLB_LBUT_WIGHT*factoryX,GLB_LBUT_HEIGHT*factoryY);
    ui->buttonOk->setGeometry((GLB_SCR_WIGHT-(GLB_EDGE_WIGHT+GLB_BAS_WIGHT*1+GLB_LBUT_WIGHT*2))*factoryX,0*factoryY,GLB_LBUT_WIGHT*factoryX,GLB_LBUT_HEIGHT*factoryY);
    ui->buttonCancel->setGeometry((GLB_SCR_WIGHT-(GLB_EDGE_WIGHT+GLB_BAS_WIGHT*0+GLB_LBUT_WIGHT*1))*factoryX,0*factoryY,GLB_LBUT_WIGHT*factoryX,GLB_LBUT_HEIGHT*factoryY);
}

//初始化窗体控件样式
void PatternManageWidget::initControlStyle()
{
    SetStyle setControlStyle;
    setControlStyle.setUiName(this->objectName());

    //背景图
    QString frameBackImgPath = setControlStyle.getStyleSheet1(this->objectName());
    ui->frameBack->setStyleSheet(frameBackImgPath);

    //label样式
    ui->labelMainTitle->setFont(fontSize_L());
    ui->labelMainTitle->setStyleSheet(titleTextColour());
    ui->labelSubTitle->setFont(fontSize_M());
    ui->labelSubTitle->setStyleSheet(noteTextColour());
    ui->labelPage->setFont(fontSize_M());
    ui->labelPage->setStyleSheet(commonTextColour());

    ui->labelPatternView->setStyleSheet(transparentStyle());
    ui->labelNameValue->setFont(fontSize_M());
    ui->labelNameValue->setStyleSheet(titleTextColour());
    ui->labelX->setFont(fontSize_M());
    ui->labelX->setStyleSheet(titleTextColour());
    ui->labelXValue->setFont(fontSize_M());
    ui->labelXValue->setStyleSheet(titleTextColour());
    ui->labelY->setFont(fontSize_M());
    ui->labelY->setStyleSheet(titleTextColour());
    ui->labelYValue->setFont(fontSize_M());
    ui->labelYValue->setStyleSheet(titleTextColour());
    ui->labelW->setFont(fontSize_M());
    ui->labelW->setStyleSheet(titleTextColour());
    ui->labelWValue->setFont(fontSize_M());
    ui->labelWValue->setStyleSheet(titleTextColour());
    ui->labelH->setFont(fontSize_M());
    ui->labelH->setStyleSheet(titleTextColour());
    ui->labelHValue->setFont(fontSize_M());
    ui->labelHValue->setStyleSheet(titleTextColour());
    ui->labelC->setFont(fontSize_M());
    ui->labelC->setStyleSheet(titleTextColour());
    ui->labelCValue->setFont(fontSize_M());
    ui->labelCValue->setStyleSheet(titleTextColour());
    ui->labelN->setFont(fontSize_M());
    ui->labelN->setStyleSheet(titleTextColour());
    ui->labelNValue->setFont(fontSize_M());
    ui->labelNValue->setStyleSheet(titleTextColour());

    ui->framePageBtn->setStyleSheet(transparentStyle());
    ui->frameRightUp->setStyleSheet(transparentStyle());

    ui->buttonSelectAll->setStyleSheet(backIconStyle());;
    ui->buttonSelectAll->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonSelectAll->objectName()));

    ui->buttonBackUpDir->setStyleSheet(backIconStyle());;
    ui->buttonBackUpDir->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonBackUpDir->objectName()));

    ui->buttonNewFolder->setStyleSheet(backIconStyle());;
    ui->buttonNewFolder->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonNewFolder->objectName()));

    //四个按钮样式表一样
    ui->buttonPgUp->setStyleSheet(confirmIconStyle());
    ui->buttonPgUp->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonPgUp->objectName()),12);

    ui->buttonPgDn->setStyleSheet(confirmIconStyle());
    ui->buttonPgDn->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonPgDn->objectName()),12);

    ui->buttonOk->setStyleSheet(confirmIconStyle());
    ui->buttonOk->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonOk->objectName()),12);

    ui->buttonCancel->setStyleSheet(confirmIconStyle());
    ui->buttonCancel->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonCancel->objectName()),12);
}

//设置类型图标
void PatternManageWidget::setTypeLogo(QString tStyle)
{
    ui->buttonTypeLogo->setUnPreBtnLogo(tStyle);
}

//设置主title
void PatternManageWidget::setMainTitle(QString str)
{
    ui->labelMainTitle->setText(str);
}

//设置副title
void PatternManageWidget::setSubTitle(QString str)
{
    ui->labelSubTitle->setText(str);
}

//初始化当前路径花样(点击选择花样时刷新)
void PatternManageWidget::initDirPath(QString path)
{
    int flag = -1;//该路径下是否存在dst文件或dsr文件的扫描标志
    m_curPath = path;
    if(m_curPath == m_usbPath || m_curPath == m_rootPath)//如果当前目录等于优盘目录或操作屏根目录，返回上级按钮不可按
    {
        ui->buttonBackUpDir->setEnabled(false);
    }
    else
    {
        ui->buttonBackUpDir->setEnabled(true);
    }

    m_fileItemList.clear();//文件列表清空
    QDir dir(m_curPath);
    //打开路径
    if(!dir.exists())
    {
        m_curPages = 0;
        m_pageNums = 0;
        return;
    }

    FileItem item;
    QString fileName;
    QString filePath;
    QString imagePath;

    dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);  // 设置类型过滤器，只为文件夹和文件格式
    dir.setSorting(QDir::DirsFirst | QDir::IgnoreCase);  //设置排序方式，文件夹优先

    QFileInfoList fileList = dir.entryInfoList();
    int count = fileList.count();
    for(int i = 0; i < count; i++)
    {
        QFileInfo fileInfo = fileList[i];

        if(fileInfo.isDir())//为文件夹
        {
            filePath = fileInfo.absoluteFilePath();
            fileName = fileInfo.baseName();
            imagePath = ":/images/folder.png";
            item.setFileInfo(filePath,fileName,imagePath);
            m_fileItemList.append(item);
        }
        else//为文件
        {
            QString suffix = fileInfo.suffix().toUpper();
            if(suffix == "DST" || suffix == "DSR" || suffix == "QUI" || suffix == "QUIX" || suffix == "PLT" || suffix == "DXF")
            {
                filePath = fileInfo.absoluteFilePath();
                fileName = fileInfo.fileName();
                imagePath = ":/images/file.png";
                item.setFileInfo(filePath,fileName,imagePath);
                m_fileItemList.append(item);
                flag = 1;//扫描到dst或dsr
            }
        }
    }

    if(flag == -1)//未扫描到dst或dsr
    {
        ui->buttonSelectAll->setEnabled(false);
    }
    else//扫描到dst或dsr
    {
        ui->buttonSelectAll->setEnabled(true);
    }

    refreshUi();
}

void PatternManageWidget::initExecDirPath(QString path)
{
    m_curPath = path;
    if(m_curPath == m_usbPath || m_curPath == m_rootPath)//如果当前目录等于优盘目录或操作屏根目录，返回上级按钮不可按
    {
        ui->buttonBackUpDir->setEnabled(false);
    }
    else
    {
        ui->buttonBackUpDir->setEnabled(true);
    }

    m_fileItemList.clear();//文件列表清空
    QDir dir(m_curPath);
    //打开路径
    if(!dir.exists())
    {
        m_curPages = 0;
        m_pageNums = 0;
        return;
    }

    FileItem item;
    QString fileName;
    QString filePath;
    QString imagePath;

    dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);  // 设置类型过滤器，只为文件夹和文件格式

    QFileInfoList fileList = dir.entryInfoList();
    int count = fileList.count();
    for(int i = 0; i < count; i++)
    {
        QFileInfo fileInfo = fileList[i];

        if(fileInfo.isDir())//为文件夹
        {
            filePath = fileInfo.absoluteFilePath();
            fileName = fileInfo.baseName();
            imagePath = ":/images/folder.png";
            item.setFileInfo(filePath,fileName,imagePath);
            m_fileItemList.append(item);
        }
    }

    refreshUi();
}

//刷新界面显示
void PatternManageWidget::refreshUi()
{
    if(m_manageMode == MANAGE_IMPORT_EXEC || m_manageMode == MANAGE_EXPORT_EXEC)
    {
        QString path = m_curPath;
        if(m_manageMode == MANAGE_IMPORT_EXEC)
        {
            path = path.remove(m_rootPath);
        }
        if(m_manageMode == MANAGE_EXPORT_EXEC)
        {
            path = path.remove(m_usbPath);
        }
        setSubTitle(path);
    }

    int itemNum;
    if (m_fileItemList.size() <= 0)
    {
        itemNum = 0;

        for (int i = 0; i < m_itemPerPage; i++)
        {
            m_itemBtnList.at(i)->hide();
        }
        ui->labelPage->setText("pageNum: 0/0");
        ui->buttonPgUp->setEnabled(false);
        ui->buttonPgDn->setEnabled(false);
        ui->buttonOk->setEnabled(false);
        ui->buttonSelectAll->setEnabled(false);

        return;
    }
    else
    {
        itemNum = m_fileItemList.size();
    }

    m_pageNums = (itemNum + m_itemPerPage - 1)/m_itemPerPage;// 计算页数
    if (m_curPages > m_pageNums)// 当前页
    {
        m_curPages = m_pageNums;
    }
    if (m_curPages <= 1 && itemNum != 0)
    {
        m_curPages = 1;
    }

    int itemidx = (m_curPages - 1) * m_itemPerPage;

    for (int i = 0; i < m_itemPerPage; i++)
    {
        if (itemidx < itemNum)
        {
            //设置图标和文件名
            m_itemBtnList[i]->setItemLeftIcon(m_fileItemList.at(itemidx).getImagePath());
            m_itemBtnList[i]->setLabelName(m_fileItemList.at(itemidx).getShowInfo());
            m_itemBtnList.at(i)->show();

            itemidx++;
        }
        else
        {
            m_itemBtnList.at(i)->hide();
        }
    }

    // 翻页按钮
    if (m_curPages <= 1)
    {
        ui->buttonPgUp->setEnabled(false);
    }
    else
    {
        ui->buttonPgUp->setEnabled(true);
    }
    if (m_curPages >= m_pageNums)
    {
        ui->buttonPgDn->setEnabled(false);
    }
    else
    {
        ui->buttonPgDn->setEnabled(true);
    }

    // 页信息
    if(m_pageNums == 0)
    {
        m_curPages = 0;
    }

    QString str = tr("pageNum: ") + QString("%1/%2").arg(m_curPages).arg(m_pageNums);//页数:
    ui->labelPage->setText(str);

    refreshCheckedPage();
}

QString PatternManageWidget::detectUsb()
{
    QString usbPath = "";

#ifdef Q_OS_LINUX
    QDir dir(LINUXUSBPATH);
    if(!dir.exists())
    {
        usbPath = "";
    }
    else
    {
        usbPath = LINUXUSBPATH;
    }
#endif

#ifdef Q_OS_WIN
    QFileInfoList list =  QDir::drives();

    for(int i = 0; i<list.count(); i++)
    {
        UINT ret = GetDriveType((WCHAR *) list.at(i).filePath().utf16());
        if(ret == DRIVE_REMOVABLE)
        {
            usbPath = list.at(i).filePath();
            break;
        }
    }
#endif
    return usbPath;
}

void PatternManageWidget::refreshCheckedPage()
{
    int idx = (m_curPages - 1) * m_itemPerPage;

    // 刷新页面中被选择的条目
    for(int var = 0; var < m_itemPerPage; var++)
    {
        if((idx + var) < m_fileItemList.size())
        {
            QString name = m_fileItemList.at(idx + var).getFilePath();

            int index = m_selectFileItemList.indexOf(name);
            if(index != -1)
            {
                // 条目被选中
                m_itemBtnList.at(var)->setCheckable(true);
                m_itemBtnList.at(var)->setChecked(true);
            }
            else
            {
                // 不被选中
                m_itemBtnList.at(var)->setChecked(false);
                m_itemBtnList.at(var)->setCheckable(false);
            }
        }
    }
}

//点击某一条目        lxs走到最新的
void PatternManageWidget::clickItem(int idx)
{
    //全选时点击条目，全选标志置为非全选
    if(m_selectAll == 1)
    {
        m_selectAll = m_selectAll * -1;
    }

    if(idx < 0)  //都不选中
    {
        m_selectAll = -1;
        m_selectFileItemList.clear();
        // 刷新页面中被选择的条目
        for (int var = 0; var < m_itemPerPage ; var++)
        {
            // 不被选中
            m_itemBtnList[var]->setChecked(false);
            m_itemBtnList[var]->setCheckable(false);
            ui->buttonOk->setEnabled(false);
        }
        //清空图片
        QPixmap pix = QPixmap();
        ui->labelPatternView->setPixmap(pix);
        clearFileInfo();
    }
    else
    {
        // 计算当前选择按钮对应的花版
        int itemidx = (m_curPages - 1) * m_itemPerPage + idx - 1;

        if (m_fileItemList.size() <= 0)
        {
            itemidx = -1;
            return;
        }
        else
        {

            if (itemidx >= m_fileItemList.size())
            {
                return;
            }
        }

        QString filePath = m_fileItemList.at(itemidx).getFilePath();
        QFileInfo fileInfo(filePath);

        QString fileName = fileInfo.fileName();
        int size = fileName.length();
        if(size > NAMEMAXLENGTH)//花样名称过长时截取
        {
            fileName = fileName.mid(0,NAMEMAXLENGTH) + "~";
        }

        if(fileInfo.isDir())//为文件夹
        {
            if(m_manageMode == MANAGE_IMPORT_EXEC || m_manageMode == MANAGE_EXPORT_EXEC)
            {
                initExecDirPath(filePath);
            }
            else
            {
                initDirPath(filePath);
            }
            clickItem(-1);
        }
        else
        {
            int retIdx = m_selectFileItemList.indexOf(filePath);

            if(retIdx == -1)
            {
                // 没有找到相同的文件名
                // 添加条目
                m_selectFileItemList.append(filePath);
            }
            else
            {
                m_selectFileItemList.takeAt(retIdx);
            }
            refreshCheckedPage();

            if(m_selectFileItemList.size() > 0)
            {
                QFileInfo lfileInfo(m_selectFileItemList.last()); //最后一个选中Item
                QString fileNamePath = lfileInfo.absoluteFilePath();
                QString suffix = lfileInfo.suffix();//后缀

                QImage image(QSize(ui->labelPatternView->width(), ui->labelPatternView->height()),QImage::Format_ARGB32);
                ui->labelNameValue->setText(lfileInfo.fileName());

                if(suffix.toUpper() == "DST")
                {
                    DataFileDst dst;
                    dst.initFile(fileNamePath);//最后一个选中Item
                    dst.createPreviewImage(&image, 0, PEN_WIDTH,1);// 生成预览文件,第2个参数为0不保存图片，1为保存图片
                    //刷新文件信息
                    ui->labelNValue->setText(QString::number(dst.getStitchNums()));

                    double width = dst.getDatWidth()*0.01;
                    ui->labelWValue->setText(QString("%1").arg(width));

                    double height = dst.getDatHeight()*0.01;
                    ui->labelHValue->setText(QString("%1").arg(height));

                    double xPos = dst.getMaxX()*0.01;
                    ui->labelXValue->setText(QString("%1").arg(xPos));

                    double yPos = dst.getMaxY()*0.01;
                    ui->labelYValue->setText(QString("%1").arg(yPos));
                }
                else if(suffix.toUpper() == "DSR")
                {
                    DataFileDsr dsr;
                    dsr.initFile(fileNamePath);//最后一个选中Item
                    dsr.convertDataToEmbAbs();
                    dsr.createPreviewImage(&image, 0, PEN_WIDTH,1);// 生成预览文件,第2个参数为0不保存图片，1为保存图片
                    //刷新文件信息
                    ui->labelNValue->setText(QString::number(dsr.getStitchNums()));

                    double width = dsr.getDatWidth()*0.01;
                    ui->labelWValue->setText(QString("%1").arg(width));

                    double height = dsr.getDatHeight()*0.01;
                    ui->labelHValue->setText(QString("%1").arg(height));

                    double xPos = dsr.getMaxX()*0.01;
                    ui->labelXValue->setText(QString("%1").arg(xPos));

                    double yPos = dsr.getMaxY()*0.01;
                    ui->labelYValue->setText(QString("%1").arg(yPos));
                }
                else if(suffix == "QUI")
                {
                    DataFileQui qui;
                    qui.initFile(fileNamePath);//最后一个选中Item
                    qui.convertDataToEmbAbs();
                    qui.createPreviewImage(&image, 0, PEN_WIDTH,1);// 生成预览文件,第2个参数为0不保存图片，1为保存图片

                    //刷新文件信息
                    ui->labelNValue->setText(QString::number(qui.getStitchNums()));

                    double width = qui.getDatWidth()*0.01;
                    ui->labelWValue->setText(QString("%1").arg(width));

                    double height = qui.getDatHeight()*0.01;
                    ui->labelHValue->setText(QString("%1").arg(height));

                    double xPos = qui.getMaxX()*0.01;
                    ui->labelXValue->setText(QString("%1").arg(xPos));

                    double yPos = qui.getMaxY()*0.01;
                    ui->labelYValue->setText(QString("%1").arg(yPos));

                }
                else if(suffix == "QUIX")
                {
                    DataFileQuix quix;
                    quix.initFile(fileNamePath);//最后一个选中Item
                    quix.convertDataToEmbAbs();
                    quix.createPreviewImage(&image, 0, PEN_WIDTH,1);// 生成预览文件,第2个参数为0不保存图片，1为保存图片

                    //刷新文件信息
                    ui->labelNValue->setText(QString::number(quix.getStitchNums()));

                    double width = quix.getDatWidth()*0.01;
                    ui->labelWValue->setText(QString("%1").arg(width));

                    double height = quix.getDatHeight()*0.01;
                    ui->labelHValue->setText(QString("%1").arg(height));

                    double xPos = quix.getMaxX()*0.01;
                    ui->labelXValue->setText(QString("%1").arg(xPos));

                    double yPos = quix.getMaxY()*0.01;
                    ui->labelYValue->setText(QString("%1").arg(yPos));

                }
                else if(suffix.toUpper() == "PLT")
                {
                    ImportHPGL importHPGL;
                    if (importHPGL.IsSecretFile(fileNamePath) == true)
                    {
                        // 文件路径
                        QDir apppath(qApp->applicationDirPath());
                        QString strSecretFile = apppath.path() + apppath.separator() + "Secret.plt";

                        importHPGL.BitMapDtat(fileNamePath,strSecretFile);
                        importHPGL.IniPara();
                        importHPGL.ReadSecretFile(strSecretFile);
                    }
                    else
                    {
                        importHPGL.IniPara();
                        importHPGL.Read(fileNamePath);
                    }
                    importHPGL.convertDataToEmbAbs();
                    importHPGL.createPreviewImage(&image, 0, PEN_WIDTH,1);// 生成预览文件,第2个参数为0不保存图片，1为保存图片

                }
                else if(suffix == "DXF")
                {
                }

                QPixmap pix = QPixmap::fromImage(image);
                ui->labelPatternView->setPixmap(pix);
            }
            else
            {
                QPixmap pix = QPixmap();
                ui->labelPatternView->setPixmap(pix);
                //清空文件信息
                clearFileInfo();
            }
        }
    }

    if(m_manageMode == MANAGE_IMPORT_EXEC || m_manageMode == MANAGE_EXPORT_EXEC)
    {
        //清空图片
        QPixmap pix = QPixmap();
        ui->labelPatternView->setPixmap(pix);
        //清空文件信息
        clearFileInfo();
        ui->buttonOk->setEnabled(true); //导入导出文件
    }
    else//选择文件
    {
        if(m_selectFileItemList.size() <= 0)
        {
            ui->buttonOk->setEnabled(false);

            //清空图片
            QPixmap pix = QPixmap();
            ui->labelPatternView->setPixmap(pix);
        }
        else
        {
            ui->buttonOk->setEnabled(true);
        }
    }
}

void PatternManageWidget::patternImportOrExport(QString mainStr,QString subStr,QString path)
{
    QDir apppath(qApp->applicationDirPath());

    if(m_curPath.length() <= 0)
    {
        return;
    }

    PromptDialog promptDlg(this);
    promptDlg.setRange(0, m_cpSelectFileItemList.size()-1);
    promptDlg.show();
    s16 showFlag = 1;

    for(int i = 0; i < m_cpSelectFileItemList.size(); i++)
    {
        QFileInfo fileInfo(m_cpSelectFileItemList.at(i));
        QString fileName = fileInfo.fileName();
        QString suffix = fileInfo.suffix();
        QString newFileName = m_curPath + apppath.separator() + fileName;

        //非5.2和6.3版本的dsr不可导入
        //dst格式错误不可导入
        if(suffix.toUpper() == "DSR" ||
           suffix.toUpper() == "DST" ||
           suffix.toUpper() == "QUI" ||
           suffix.toUpper() == "QUIX" ||
           suffix.toUpper() == "PLT" ||
           suffix.toUpper() == "DXF" )
        {
            int rel = 0;
            if(suffix.toUpper() == "DSR")
            {
                DataFileDsr dsr;
                dsr.initFile(m_cpSelectFileItemList.at(i));
                rel = dsr.checkDsrVersion();
            }
            else if(suffix.toUpper() == "DST")
            {
                DataFileDst dst;
                dst.initFile(m_cpSelectFileItemList.at(i));
                rel = dst.checkDstFile();
            }
            else if(suffix.toUpper() == "QUI")
            {
            }
            else if(suffix.toUpper() == "QUIX")
            {
            }
            else if(suffix.toUpper() == "PLT")
            {
            }
            else if(suffix.toUpper() == "DXF")
            {
            }

            if(rel < 0)
            {
                promptDlg.initDialog(PromptDialog::BTN_OK);
                promptDlg.setTitleStr(tr("Prompt"));

                QString str;
                if(rel == -2)
                {
                    str = fileName  + " " + tr("Over 1.28 million stitches, can not be imported!");//针数超过128万，不能导入！
                }
                else
                {
                    str = fileName  + " " + tr("Format error, can not be imported!");//格式错误，不能导入！
                }
                promptDlg.setContentStr(str);
                promptDlg.exec();
                showFlag = 0;
                continue;
            }
        }

        qDebug()<<"Pattern ImportOrExport";
        qDebug()<<"fileName"<<fileName;
        qDebug()<<"newFileName"<<newFileName;

        QFile file(newFileName);
        if(file.exists() == true)//花样导入或导出，存在u盘里或datafiles路径的花版
        {
            promptDlg.initDialog(PromptDialog::BTN_R_R_S);
            promptDlg.setTitleStr(tr("Prompt"));

            QString str;
            str = fileName  + " " + tr("This file already exists!");//此文件已存在！
            promptDlg.setContentStr(str);
            int ret = promptDlg.exec();
            showFlag = 0;
            if(ret == 1)//重命名
            {
                WordsInputDialog wordInputDlg;
                wordInputDlg.clean();
                wordInputDlg.setTitleStr(tr("Rename"));//重命名

                int size = fileName.length();
                if(size > NAMEMAXLENGTH + 12)//花样名称过长时截取
                {
                    fileName = fileName.mid(0,NAMEMAXLENGTH + 12) + "~";
                }

                wordInputDlg.setOldWordsStr(fileName);
                if(wordInputDlg.exec() == 1)
                {
                    if(m_manageMode == MANAGE_IMPORT)//导入文件
                    {
                        //文件名称
                        QString name = wordInputDlg.getInputStr();
                        QString newName = m_curPath + apppath.separator() + name + "." + suffix;
                        QFile::copy(m_cpSelectFileItemList.at(i), newName);
                        QFile::copy(m_cpSelectFileItemList.at(i) + ".fcg", newName + ".fcg");
                    }
                    else if(m_manageMode == MANAGE_EXPORT)//导出文件
                    {
                        //文件名称
                        QString name = wordInputDlg.getInputStr();//导出文件路径
                        QString newName = m_curPath + apppath.separator() + name + "." + suffix;
                        QFile::copy(m_cpSelectFileItemList.at(i), newName);
                        QFile::copy(m_cpSelectFileItemList.at(i) + ".fcg", newName + ".fcg");
                        QFile::copy(m_cpSelectFileItemList.at(i) + ".ds16", newName + ".ds16");
                    }
                }
            }
            else if(ret == 2)//替换
            {
                if(m_manageMode == MANAGE_IMPORT)//导入文件
                {
                    QFile::remove(newFileName);
                    QFile::remove(newFileName + ".fcg");
                    QFile::remove(newFileName + ".ds16");
                    QFile::copy(m_cpSelectFileItemList.at(i), newFileName);
                    emit  siReplacePattrn(newFileName);
                    //newFileName = D:/work/workQT/XPlatform/Windows/debug/datafiles\0.7盾牌.dst
                    //QFile::copy(m_cpSelectFileItemList.at(i) + ".fcg", newFileName + ".fcg");
                }
                else if(m_manageMode == MANAGE_EXPORT)//导出文件
                {
                    QFile::remove(newFileName);
                    QFile::remove(newFileName + ".fcg");
                    QFile::copy(m_cpSelectFileItemList.at(i), newFileName);
                    QFile::copy(m_cpSelectFileItemList.at(i) + ".fcg", newFileName + ".fcg");
                    QFile::copy(m_cpSelectFileItemList.at(i) + ".ds16", newFileName + ".ds16");
                }
            }
        }
        else
        {
            promptDlg.initDialog(PromptDialog::BTN_P_NONE);
            promptDlg.setTitleStr(tr("Prompt"));

            if(m_manageMode == MANAGE_IMPORT)//导入文件
            {
                promptDlg.setContentProcessStr(tr("Importing ") + fileName); //正在导入
            }
            else if(m_manageMode == MANAGE_EXPORT)//导出文件
            {
                promptDlg.setContentProcessStr(tr("Exporting ") + fileName); //正在导出
            }

            if(showFlag == 0)
            {
                promptDlg.show();
                showFlag = 1;
            }
            if(m_manageMode == MANAGE_IMPORT)//导入文件
            {
                QFile::copy(m_cpSelectFileItemList.at(i),newFileName);
                //QFile::copy(m_cpSelectFileItemList.at(i) + ".fcg", newFileName + ".fcg");
            }
            else if(m_manageMode == MANAGE_EXPORT)//导出文件
            {
                QFile::copy(m_cpSelectFileItemList.at(i),newFileName);
                QFile::copy(m_cpSelectFileItemList.at(i) + ".fcg", newFileName + ".fcg");
                QFile::copy(m_cpSelectFileItemList.at(i) + ".ds16", newFileName + ".ds16");
            }

        }

        qDebug()<<"processEvents before";
        QCoreApplication::processEvents(QEventLoop::AllEvents);
        qDebug()<<"processEvents end";

        if(m_manageMode == MANAGE_IMPORT)//导入文件
        {
            QImage image(m_imgSize,QImage::Format_ARGB32);

            if(suffix.toUpper() == "DST")
            {
                DataFileDst dst;
                dst.initFile(newFileName);
                dst.createPreviewImage(&image, 1, PEN_WIDTH);// 生成渐进绘制预览图片,第2个参数为0不保存图片，1为保存图片

                qDebug()<<"dst.createPreviewImage end";
            }
            else if(suffix.toUpper() == "DSR")
            {
                DataFileDsr dsr;
                dsr.initFile(newFileName);
                dsr.convertDataToEmbAbs();
                dsr.createPreviewImage(&image, 1, PEN_WIDTH);// 生成渐进绘制预览图片,第2个参数为0不保存图片，1为保存图片
            }
            else if(suffix.toUpper() == "QUI")
            {
            }
            else if(suffix.toUpper() == "QUIX")
            {
            }
            else if(suffix.toUpper() == "PLT")
            {
            }
            else if(suffix.toUpper() == "DXF")
            {
            }
        }

        promptDlg.setValue(i);
    }

#ifdef Q_OS_LINUX
    system("sync");
#endif
    if(m_manageMode == MANAGE_IMPORT)//导入文件
    {
        promptDlg.setContentStr(tr("Import complete")); //导入完成
    }
    else if(m_manageMode == MANAGE_EXPORT)//导出文件
    {
        promptDlg.setContentStr(tr("Export complete")); //导出完成
    }
    promptDlg.hide();

    setMainTitle(mainStr);
    setSubTitle(subStr);
    initialize();
    initDirPath(path);
    clickItem(-1);
    ui->buttonSelectAll->show();
    ui->buttonNewFolder->hide();
}

void PatternManageWidget::patternDelete()
{
    if(m_selectAll == 1)//全选时删除整个文件夹
    {
        for(int i = 0; i < m_selectFileItemList.size(); i++)
        {
            QFile::remove(m_selectFileItemList.at(i));
            QFile::remove(m_selectFileItemList.at(i)+".fcg");
            QFile::remove(m_selectFileItemList.at(i)+".ds16");
            QFile::remove(m_selectFileItemList.at(i)+".ds8");
            QFile::remove(m_selectFileItemList.at(i)+".preview.png");
        }

        if(m_curPath != m_rootPath)//非根目录
        {
            //得到上级目录
            QDir upDir(m_curPath);
            upDir.cdUp();
            QString upPath = upDir.absolutePath();

            QDir remDir(m_curPath);
            if(remDir.exists() == true)
            {
                remDir.rmpath(remDir.absolutePath());//删除整个文件夹
            }

            initDirPath(upPath);//初始化上级目录
        }
        else
        {
            initDirPath(m_curPath);//初始化当前目录(根目录)
        }
    }
    else
    {
        //所选文件个数等于目录文件总个数时删除整个文件夹
        if(m_selectFileItemList.size() == m_fileItemList.size())
        {
            for(int i = 0; i < m_selectFileItemList.size(); i++)
            {
                QFile::remove(m_selectFileItemList.at(i));
                QFile::remove(m_selectFileItemList.at(i)+".fcg");
                QFile::remove(m_selectFileItemList.at(i)+".ds16");
                QFile::remove(m_selectFileItemList.at(i)+".ds8");
                QFile::remove(m_selectFileItemList.at(i)+".preview.png");
            }

            if(m_curPath != m_rootPath)//非根目录
            {
                //得到上级目录
                QDir upDir(m_curPath);
                upDir.cdUp();
                QString upPath = upDir.absolutePath();

                QDir remDir(m_curPath);
                if(remDir.exists() == true)
                {
                    remDir.rmpath(remDir.absolutePath());//删除整个文件夹
                }

                initDirPath(upPath);//初始化上级目录
            }
            else
            {
                initDirPath(m_curPath);//初始化当前目录(根目录)
            }
        }
        else
        {
            //所选文件个数不等于目录文件总个数时删除整个文件夹
            for(int i = 0; i < m_selectFileItemList.size(); i++)
            {
                QFile::remove(m_selectFileItemList.at(i));
                QFile::remove(m_selectFileItemList.at(i)+".fcg");
                QFile::remove(m_selectFileItemList.at(i)+".ds16");
                QFile::remove(m_selectFileItemList.at(i)+".ds8");
                QFile::remove(m_selectFileItemList.at(i)+".preview.png");
                initDirPath(m_curPath);
            }
        }
    }
    clickItem(-1);
}

void PatternManageWidget::clearFileInfo()
{
    ui->labelNameValue->setText("");
    ui->labelNValue->setText("");
    ui->labelCValue->setText("");
    ui->labelWValue->setText("");
    ui->labelHValue->setText("");
    ui->labelXValue->setText("");
    ui->labelYValue->setText("");
}

//花样导入
void PatternManageWidget::patternManage(MANAGE_MODE mode)
{
    initialize();
    if(mode != MANAGE_DELETE)//删除操作不检测优盘
    {
        m_usbPath.clear();
        m_usbPath = detectUsb();
        if(m_usbPath.length() <= 0)
        {
            //优盘不存在
            PromptDialog dlg(this);
            dlg.initDialog(PromptDialog::BTN_OK);
            dlg.setTitleStr(tr("Prompt"));

            QString str;
            str = tr("USB flash drive is not detected!");//未检测到优盘！
            dlg.setContentStr(str);
            dlg.exec();
            return;
        }
    }

    if(mode == MANAGE_IMPORT)
    {
        initDirPath(m_usbPath);
    }
    else
    {
        initDirPath(m_rootPath);
    }
    clickItem(-1);

    m_manageMode = mode;//花样导入、导出、删除
    ui->buttonNewFolder->hide();
    ui->buttonSelectAll->show();
    this->show();
}

void PatternManageWidget::setImportImageSize(QSize imgSize)
{
    m_imgSize = imgSize;
}

void PatternManageWidget::on_button1_clicked()
{
    clickItem(1);
}

void PatternManageWidget::on_button2_clicked()
{
    clickItem(2);
}

void PatternManageWidget::on_button3_clicked()
{
    clickItem(3);
}

void PatternManageWidget::on_button4_clicked()
{
    clickItem(4);
}

void PatternManageWidget::on_button5_clicked()
{
    clickItem(5);
}

void PatternManageWidget::on_button6_clicked()
{
    clickItem(6);
}

void PatternManageWidget::on_button7_clicked()
{
    clickItem(7);
}

void PatternManageWidget::on_button8_clicked()
{
    clickItem(8);
}

void PatternManageWidget::on_button9_clicked()
{
    clickItem(9);
}

void PatternManageWidget::on_button10_clicked()
{
    clickItem(10);
}

void PatternManageWidget::on_button11_clicked()
{
    clickItem(11);
}

void PatternManageWidget::on_button12_clicked()
{
    clickItem(9);
}

void PatternManageWidget::on_button13_clicked()
{
    clickItem(10);
}

void PatternManageWidget::on_button14_clicked()
{
    clickItem(11);
}

void PatternManageWidget::on_button15_clicked()
{
    clickItem(12);
}

void PatternManageWidget::on_button16_clicked()
{

    clickItem(13);
}

void PatternManageWidget::on_button17_clicked()
{
    clickItem(14);
}

void PatternManageWidget::on_button18_clicked()
{
    clickItem(15);
}

void PatternManageWidget::on_button19_clicked()
{
    clickItem(16);
}

void PatternManageWidget::on_button20_clicked()
{
    clickItem(20);
}

void PatternManageWidget::on_button21_clicked()
{
    clickItem(21);
}

void PatternManageWidget::on_button22_clicked()
{
    clickItem(22);
}

void PatternManageWidget::on_buttonPgUp_clicked()
{
    m_curPages--;
    refreshUi();
}

void PatternManageWidget::on_buttonPgDn_clicked()
{
    m_curPages++;
    refreshUi();
}

void PatternManageWidget::on_buttonOk_clicked()
{
    if(m_manageMode == MANAGE_DELETE)//花样删除
    {
        //是否删除花样的提示
        PromptDialog dlg(this);
        dlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        dlg.setTitleStr(tr("Prompt"));

        qDebug()<<"import begin 1";
        QString str;
        str = tr("Whether to delete the pattern?");//是否删除花样?
        dlg.setContentStr(str);
        if(dlg.exec() == 1)
        {
            patternDelete();
            emit siDeletePattern();//删除文件后判断当前文件是否被删除
        }
    }
    else
    {
        qDebug()<<"import begin 1.5";
        QString str;
        QString path;
        if(m_manageMode == MANAGE_IMPORT)//花样导入
        {
            qDebug()<<"import begin 2";

            str = tr("Operation screen");//操作屏
            //导入路径
            path = m_rootPath;
            m_manageMode = MANAGE_IMPORT_EXEC;
            m_cpSelectFileItemList.clear();
            m_cpSelectFileItemList.append(m_selectFileItemList);

            qDebug()<<"import begin 2.5";
        }
        else if(m_manageMode == MANAGE_EXPORT)//花样导出
        {
            qDebug()<<"import begin XXX";

            str = tr("USB");//优盘
            //导出路径
            path = m_usbPath;
            m_manageMode = MANAGE_EXPORT_EXEC;
            m_cpSelectFileItemList.clear();
            m_cpSelectFileItemList.append(m_selectFileItemList);
            qDebug()<<"import begin 3.5";
        }
        else if(m_manageMode == MANAGE_IMPORT_EXEC)//花样导入执行
        {

            qDebug()<<"import begin 4";
            m_manageMode = MANAGE_IMPORT;
            QString mainStr,subStr,path;
            mainStr = tr("Pattern Import");
            subStr = tr("Pattern Import < Pattern setting");
            path = m_usbPath;
            patternImportOrExport(mainStr,subStr,path);

            return;
            qDebug()<<"import begin 4.5";
        }
        else if(m_manageMode == MANAGE_EXPORT_EXEC)//花样导出执行
        {

            qDebug()<<"import begin 5";
            m_manageMode = MANAGE_EXPORT;
            QString mainStr,subStr,path;
            mainStr = tr("Pattern Export");
            subStr = tr("Pattern Export < Pattern setting");
            path = m_rootPath;
            patternImportOrExport(mainStr,subStr,path);

            return;
            qDebug()<<"import begin 5.5";
        }

        ui->buttonNewFolder->show();
        ui->buttonSelectAll->hide();
        setMainTitle(str);
        setSubTitle(path);
        initialize();
        initExecDirPath(path);
        clickItem(-1);
    }
}

void PatternManageWidget::on_buttonCancel_clicked()
{
    QString mainStr,subStr,path;
    if(m_manageMode == MANAGE_IMPORT ||
       m_manageMode == MANAGE_EXPORT ||
       m_manageMode == MANAGE_DELETE )//花样导入、花样导出、花样删除
    {
        this->hide();
        return;
    }
    else if(m_manageMode == MANAGE_IMPORT_EXEC)//花样导入执行
    {
        m_manageMode = MANAGE_IMPORT;
        mainStr = tr("Pattern Import");
        subStr = tr("Pattern Import < Pattern setting");
        path = m_usbPath;
    }
    else if(m_manageMode == MANAGE_EXPORT_EXEC)//花样导出执行
    {
        m_manageMode = MANAGE_EXPORT;
        mainStr = tr("Pattern Import");
        subStr = tr("Pattern Import < Pattern setting");
        path = m_rootPath;
    }

    ui->buttonNewFolder->hide();
    ui->buttonSelectAll->show();
    setMainTitle(mainStr);
    setSubTitle(subStr);
    initialize();
    initDirPath(path);
    clickItem(-1);
    //密码权限,单次有效
    g_emUser = operate;
}

void PatternManageWidget::on_buttonBackUpDir_clicked()
{
    QDir dir(m_curPath);
    dir.cdUp();//返回上级目录
    QString path = dir.absolutePath();//得到上级目录
    if(m_manageMode == MANAGE_IMPORT_EXEC || m_manageMode == MANAGE_EXPORT_EXEC)
    {
        initExecDirPath(path);
    }
    else
    {
        initDirPath(path);
    }
    clickItem(-1);
}

void PatternManageWidget::on_buttonSelectAll_clicked()
{
    m_selectAll = m_selectAll * -1;
    if(m_selectAll == 1)//全选
    {
        QDir dir(m_curPath);
        //打开路径
        if(!dir.exists())
        {
            return;
        }

        QStringList filters;
        filters<<QString("*.dst")<<QString("*.DST")
                 <<QString("*.dsr")<<QString("*.DSR")
                 <<QString("*.qui")<<QString("*.QUI")
                <<QString("*.plt")<<QString("*.PLT");
//                 <<QString("*.quix")<<QString("*.QUIX");
//                 <<QString("*.plt")<<QString("*.PLT");
//                 <<QString("*.dxf")<<QString("*.DXF");

        dir.setNameFilters(filters);  //dst、dsr文件格式
        QFileInfoList fileList = dir.entryInfoList();
        int count = fileList.count();
        for(int i = 0; i < count; i++)
        {
            QFileInfo fileInfo = fileList[i];
            m_selectFileItemList.append(fileInfo.filePath());
        }
        refreshCheckedPage();

        QFileInfo lfileInfo(m_selectFileItemList.last()); //最后一个选中Item
        QString fileNamePath = lfileInfo.absoluteFilePath();
        QString suffix = lfileInfo.suffix();//后缀

        QImage image(QSize(ui->labelPatternView->width(), ui->labelPatternView->height()),QImage::Format_ARGB32);
        ui->labelNameValue->setText(lfileInfo.fileName());

        if(suffix.toUpper() == "DST")
        {
            DataFileDst dst;
            dst.initFile(fileNamePath);//最后一个选中Item
            dst.createPreviewImage(&image, 0, PEN_WIDTH,1);// 生成预览文件,第2个参数为0不保存图片，1为保存图片
            //刷新文件信息
            ui->labelNValue->setText(QString::number(dst.getStitchNums()));

            double width = dst.getDatWidth()*0.01;
            ui->labelWValue->setText(QString("%1").arg(width));

            double height = dst.getDatHeight()*0.01;
            ui->labelHValue->setText(QString("%1").arg(height));

            double xPos = dst.getMaxX()*0.01;
            ui->labelXValue->setText(QString("%1").arg(xPos));

            double yPos = dst.getMaxY()*0.01;
            ui->labelYValue->setText(QString("%1").arg(yPos));
        }
        else if(suffix.toUpper() == "DSR")
        {
            DataFileDsr dsr;
            dsr.initFile(fileNamePath);//最后一个选中Item
            dsr.convertDataToEmbAbs();
            dsr.createPreviewImage(&image, 0, PEN_WIDTH,1);// 生成预览文件,第2个参数为0不保存图片，1为保存图片
            //刷新文件信息
            ui->labelNValue->setText(QString::number(dsr.getStitchNums()));

            double width = dsr.getDatWidth()*0.01;
            ui->labelWValue->setText(QString("%1").arg(width));

            double height = dsr.getDatHeight()*0.01;
            ui->labelHValue->setText(QString("%1").arg(height));

            double xPos = dsr.getMaxX()*0.01;
            ui->labelXValue->setText(QString("%1").arg(xPos));

            double yPos = dsr.getMaxY()*0.01;
            ui->labelYValue->setText(QString("%1").arg(yPos));
        }
        else if(suffix.toUpper() == "QUI")
        {
        }
        else if(suffix.toUpper() == "QUIX")
        {
        }
        else if(suffix.toUpper() == "PLT")
        {
        }
        else if(suffix.toUpper() == "DXF")
        {
        }

        QPixmap pix = QPixmap::fromImage(image);
        ui->labelPatternView->setPixmap(pix);
    }
    else if(m_selectAll == -1)//全不选
    {
        clickItem(m_selectAll);
    }

    if(m_selectFileItemList.size() <= 0)
    {
        ui->buttonOk->setEnabled(false);
    }
    else
    {
        ui->buttonOk->setEnabled(true);
    }
}

//新建文件夹
void PatternManageWidget::on_buttonNewFolder_clicked()
{
    WordsInputDialog wordInputDlg;
    wordInputDlg.clean();
    wordInputDlg.setTitleStr(tr("new folder"));//新文件夹
    wordInputDlg.setOldWordsStr("");
    if(wordInputDlg.exec() == 1)
    {
        //文件路径
        QString name = wordInputDlg.getInputStr();
        QDir apppath(qApp->applicationDirPath());
        QString newFolderPath = m_curPath + apppath.separator() + name;
        newFolderPath = QDir(newFolderPath).absolutePath();//为了将"\"变为"/"

        QDir dir(newFolderPath);
        if(dir.exists() == false)
        {
            dir.mkdir(newFolderPath);
            initExecDirPath(m_curPath);
        }
        else
        {
            PromptDialog dlg(this);
            dlg.initDialog(PromptDialog::BTN_OK);
            dlg.setTitleStr(tr("Prompt"));

            QString str;
            str = tr("This folder already exists!");//此文件夹已经存在！
            dlg.setContentStr(str);
            dlg.exec();
            return;
        }
    }
}

void PatternManageWidget::mousePressEvent(QMouseEvent *e)
{
    if ( e->button() == Qt::LeftButton)
    {
        m_mousePressX = e->x();
        m_mousePressY = e->y();
        m_mouseReleaseX = 0;
        m_mouseReleaseY = 0;
    }
}

void PatternManageWidget::mouseReleaseEvent(QMouseEvent *e)
{
    if ( e->button() == Qt::LeftButton)
    {
        m_mouseReleaseX = e->x();
        m_mouseReleaseY = e->y();
    }

    int width = this->width();
    int height = this->height();
    if ((m_mousePressX >= 0 && m_mousePressX <= 100)  &&
       ((m_mousePressY >= (height - 100)) && m_mousePressY <= height) &&
       ((m_mouseReleaseX >= (width - 100)) && m_mouseReleaseX <= width) &&
       ((m_mouseReleaseY >= (height - 100)) && m_mouseReleaseY <= height))
    {
        MainWidgetFunction mainFunction;
        QString usbPath;//优盘路径
        usbPath = mainFunction.detectUsb();//优盘检测
        if(usbPath.length() <= 0)
        {
            //优盘不存在
            return;
        }
        else
        {
            QPixmap pixmap=QPixmap::grabWindow(this->winId(),0,0,this->width(),this->height());//截屏存放在pixmap
            QString name_pc = usbPath +  "EMB" + //
                    QDateTime::currentDateTime().toString("yyyyMMdd") +//获取时期时间
                    +"_"+
                    QDateTime::currentDateTime().toString("hhmmss")    + ".png";

            pixmap.save(name_pc,"png"); // 路径
        }
    }

    m_mousePressX = 0;
    m_mousePressY = 0;
    m_mouseReleaseX = 0;
    m_mouseReleaseY = 0;
}
